{extend name="base"/}
{block name="main"}
<div class="Hui-article">
    <article class="cl pd-20">
         <div id="tab_demo" class="HuiTab" style="margin-top: 0px; position: relative;">
                        <div class="tabBar clearfix">
                            <span class="current" onclick="window.location.href='{:url('advert/index')}'">幻灯片</span>
                            <span onclick="window.location.href='{:url('advert/navigation')}'">导航图标</span>
                            <span onclick="window.location.href='{:url('advert/advertising')}'">广告位</span>
                            <div class="l n_tab_add"><a href="javascript:;" onclick="addSlide('增加幻灯片','addAdvert?pos_id=1','800','600')" class="n_tab_add"><i class="Hui-iconfont">&#xe600;</i> 增加幻灯片</a></div>
                        </div>
                    </div>
        <table class="table table-border table-bordered table-hover table-bg">
            <thead>
            <tr>
                <th scope="col" colspan="9">幻灯片 <span style="float: right">幻灯片总体高度：<input onchange="add_height(this.value);" type="number" class="input-text" value="{$SlideHeight}" style="width:50px;text-align: center"></span></th>
            </tr>
            <tr class="text-c">
                <th>排序</th>
                <th>幻灯片标题</th>
                <th>链接</th>
                <th>略缩图</th>
                <!--<th>高度</th>-->
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="list" id="vo"}
            <tr class="text-c">
                <td width="8">
                    <input class="input-text" value="{$vo['sort']}" onchange="addsort(this.value,'{$vo.adv_id}');" onkeyup='this.value=this.value.replace(/\D/gi,"")' type="text" style="width: 50px;text-align: center" >
                </td>
                <td>{$vo['adv_title']}</td>
                <td>{$vo['adv_url']}</td>
                <td>
                    <img width="60" class="product-thumb" src="/{$vo['adv_image']}">
                </td>
                <!--<td>-->
                    <!--<input class="input-text" onchange="add_height(this.value,'{$vo.adv_id}');" value="{$vo['adv_height']}" type="number" style="width: 50px;text-align: center">-->
                <!--</td>-->
                <td>
                    <a title="编辑" href="javascript:;" onclick="advert_edit('幻灯片编辑','updateAdvert?adv_id={$vo.adv_id}','800','600')" class="ml-5" style="text-decoration:none"><i style="font-size: 20px" class="Hui-iconfont">&#xe6df;</i></a>
                    <a title="删除" href="javascript:;" onclick="advert_del(this,'{$vo.adv_id}')" class="ml-5" style="text-decoration:none"><i style="font-size: 20px" class="Hui-iconfont">&#xe6e2;</i></a>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
    </article>
    <div class="n_page_no">
        {$page}
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    /*
     参数解释：
     title	标题
     url		请求的url
     id		需要操作的数据id
     w		弹出层宽度（缺省调默认值）
     h		弹出层高度（缺省调默认值）
     */
//添加幻灯片
function addSlide(title,url,w,h){
    layer_show(title,url,w,h);
}
//编辑幻灯片
function advert_edit(title,url,w,h){
    layer_show(title,url,w,h);
}
//删除幻灯片
function advert_del(obj,id){
    layer.confirm('确认要删除吗？',function(index){
        //此处请求后台程序，下方是成功后的后台处理……
        //删除
        $.ajax({
            type : "post",
            url : "{:url('advert/delAdvert')}",
            data : {
                "adv_id" : id,
            },
            success : function(data) {
                if (data['code'] > 0) {
                    $(obj).parents("tr").remove();
                    layer.msg(data['message'],{icon:1,time:1000});
                }else{
                    layer.msg(data['message'], {icon: 2, time: 1000});
                }
            }
        })
    });
}
function addsort(val,adv_id) {
    $.ajax({
        type : "post",
        url : "{:url('advert/AdvertPositionSort')}",
        data : {
            "sort" : val,
            "adv_id" : adv_id,
        },
        success : function(data) {
            if (data['code'] > 0) {
                layer.msg(data['message'],{icon:1,time:1000},function () {
                    window.location.reload();
                });
            }else{
                layer.msg(data['message'], {icon: 2, time: 1000});
            }
        }
    })
}
    function add_height(val) {
        console.log(val);
        $.ajax({
            type : "post",
            url : "{:url('advert/add_height')}",
            data : {
                "info" : val,
            },
            success : function(data) {
                if (data['code'] > 0) {
                    layer.msg(data['message'],{icon:1,time:1000});
                }else{
                    layer.msg(data['message'], {icon: 2, time: 1000});
                }
            }
        })
    }
</script>
{/block}